round

pure function round(): decimal

Round this decimal to the nearest whole number.

Examples:

  • (-0.4).round() returns 0

  • (0.4).round() returns 0

  • (1.49999999999999999999).round() returns 1

  • (1.5).round() returns 2

Since

0.9.1


pure function round(digits: integer): decimal

Round this decimal to a specific number of decimal places.

decimal.round(0) is equivalent to decimal.round(), i.e. rounding will be to the nearest whole number. Positive arguments round to an increasing number of decimal places, e.g. 1 rounds to the neartest tenth, 2 to the nearest hundredth, 3 to the nearest thousandth. Negative arguments round in the opposite way, i.e. -1 rounds to the nearest ten, -2 to the nearest hundred, -3 to the nearest thousand.

Examples:

  • (123.456).round(0) returns 123

  • (123.456).round(-1) returns 120

  • (123.456).round(1) returns 123.4

  • (123.456).round(-2) returns 100

  • (123.456).round(2) returns 123.45

  • (123.456).round(-3) returns 0

  • (123.456).round(3) returns 123.456

Since

0.9.1

Parameters

digits

the number of decimal places to round